package main

import (
	"fmt"
	_ "os/exec"
	"promote/study"
	_ "promote/study/structs"
	"runtime"
)

func main() {
	files()
}


func files() {
	assetType()
}

func assetType() {
	fmt.Println(`类型断言`)
	type point struct {
		x, y int
	}
	var p = &point{1, 2}
	var aI interface{}
	aI = p
	var b *point
	b = aI.(*point)
	fmt.Printf("%p %p %p %v %v %v\n", &p, &aI, &b, p, aI, b)
	
	if c, ok := aI.(*point); ok {
		fmt.Println("c", c)
	}
}

func main1() {
    fmt.Println("hello world")
	// structs.StructFunc()
	var p *int = new(int)
	var p2 *int = new(int)
	fmt.Println(p, p2 == nil)

	var s error
	s = study.NewStudyError("main.go", "错误信息", 15)
	fmt.Println(s.Error())
	
	switch s2 := s.(type) {
	case *study.StudyError:
		fmt.Println(s2.MyError())
	default:
		fmt.Println("nothing")	
	}

	fmt.Println(runtime.NumCPU())
}


func arrayTest() {
	fmt.Println("----------------")

	var a [4]int = [4]int{4,3, 2, 1}
	var b [4]int = [4]int{1,2,3,4}
	fmt.Println(&a[0], &b, a == b)
	fmt.Printf("%p\n", &a)
	for i,_ := range a {
		fmt.Println(&a[i], i)
	}
	arrayAddress(a)
}

func arrayAddress(a [4]int) {
 for i,_ := range a {
   fmt.Println(&a[i], i)
 }
}


func deferAdd() (r int) {
	defer func() { r += 3 }()

	return 12
}
